﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageWeighedTardiness : Objective
    {
        public AverageWeighedTardiness()
            : base()
        {
        }
        public AverageWeighedTardiness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }

        protected override void Logic()
        {
            double averageWeighedTardiness = 0;
            double totalWeighedTardiness = 0;

            int tardiness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                tardiness = Math.Max(0, order.EndDate - order.DueDate);
                totalWeighedTardiness = totalWeighedTardiness + (order.Weight * tardiness);
            }

            averageWeighedTardiness = totalWeighedTardiness / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageWeighedTardiness,2);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderWeightValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
            validators.Add(new OrderDueDateValidator(SchEduData));
        }


        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Weighed Tardiness";
                aboutInfo.Guid = new Guid("{A6F05695-0651-4451-BCE9-0867737C0187}");
                aboutInfo.Description = Resources.AverageWeighedTardinessDescription;
                return aboutInfo;
            }
        }

    }
}
